package com.example.communist_app_api.service.impl;

import com.example.communist_app_api.db.dao.ArticleDao;
import com.example.communist_app_api.db.pojoDto.Article;
import com.example.communist_app_api.db.pojoDto.CarouselMap;
import com.example.communist_app_api.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleDao articleDao;

    @Override
    public List<Article> getAllArticle() {
        List<Article> articles = articleDao.getAllArticle();
        if (articles == null)
        return null;
        else return articles;
    }

    @Override
    public int insertArticle(Article article) {
        int insertNum = articleDao.insertArticle(article);
        return insertNum;
    }

    @Override
    public void deleteArticle(Integer id) {
        articleDao.deleteArticle(id);
    }

    @Override
    public Article getArticleById(Integer id) {
        Article article = articleDao.getArticleById(id);
        return article;
    }

    @Override
    public List<Article> getTopArticle(Integer organizationId) {
        List<Article> articles = articleDao.getTopArticle(organizationId);
        if (articles == null)
            return null;
        else return articles;
    }

    @Override
    public Boolean updateTopArticle(Integer isTop, Integer id) {
        Boolean top = articleDao.updateTopArticle(isTop, id);
        return top;
    }

    @Override
    public List<Article> getCategorizeArticles(Integer article_type_id) {
        return articleDao.getCategorizeArticles(article_type_id);
    }

    @Override
    public boolean UpdateReading(Integer id) {
        return articleDao.UpdateReading(id);
    }

    @Override
    public int getReading(Integer id) {
        return articleDao.getReading(id);
    }

    @Override
    public List<CarouselMap> getCarouselMap() {
        return articleDao.getCarouselMap();
    }

    @Override
    public boolean isCarouselMap(Integer id) {
        return articleDao.isCarouselMap(id);
    }

    @Override
    public boolean noCarouselMap(Integer id) {
        return articleDao.noCarouselMap(id);
    }

    @Override
    public List<Article> SearchQueryArticles(String title) {
        return articleDao.SearchQueryArticles(title);
    }

    @Override
    public List<Article> getArticleByParentId(Integer organizationId) {
        return articleDao.getArticleByParentId(organizationId);
    }

    @Override
    public List<Article> getAllTopArticle() {
        return articleDao.getAllTopArticle();
    }

    @Override
    public List<Article> getOrganizationIdCategorizeArticles(Integer articleTypeId, Integer organizationId) {
        return articleDao.getOrganizationIdCategorizeArticles(articleTypeId,organizationId);
    }

    @Override
    public List<Article> SearchQueryOrganizationIdArticles(String title, Integer organizationId) {
        return articleDao.SearchQueryOrganizationIdArticles(title,organizationId);
    }
}
